import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/LoginView.vue'
import Home from '../views/HomeView.vue'
import Dashboard from '@/views/dashboard/DashboardView.vue'
import Members from '../views/members/memberView.vue'
import Task from '../views/task/taskInfo.vue'
import Message from '../views/messages/MessageView.vue'
// import Report from '../views/report/ReportView.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect: '/dashboard',
    children: [{
      path: '/dashboard',
      component: Dashboard
    },
    {
      path: '/members',
      component: Members
    },
    {
      path: '/tasks',
      component: Task
    },
    {
      path: '/messages',
      component: Message
    }
    // ,
    // {
    //   path: '/report',
    //   component: Report
    // }
    ]
  },
  {
    // 重定向
    path: '*',
    redirect: '/dashboard',
    component: Home
  }
]

const router = new VueRouter({
  routes
})
/* 全局路由首位 */
router.beforeEach((to, from, next) => {
  if (to.path === '/login') next()
  const strToken = window.sessionStorage.getItem('token')
  if (!strToken) next('/login')
  next()
})
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
export default router
